package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.GysSmlt;
import com.corpcredit.model.Jbqk;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class GysSmltForm extends BasePage implements Serializable {
    private GenericManager<GysSmlt, Long> gysSmltManager;
    private GysSmlt gysSmlt = new GysSmlt();
    private Long id;
    
    private Jbqk jbqk;

    public void setJbqk( Jbqk jbqk )
    {
        this.jbqk = jbqk;
    }
    public void setGysSmltManager(GenericManager<GysSmlt, Long> gysSmltManager) {
        this.gysSmltManager = gysSmltManager;
    }

    public GysSmlt getGysSmlt() {
        return gysSmlt;
    }

    public void setGysSmlt(GysSmlt gysSmlt) {
        this.gysSmlt = gysSmlt;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        gysSmltManager.remove(gysSmlt.getId());
        addMessage("gysSmlt.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            gysSmlt = gysSmltManager.get(id);
        } else {
            gysSmlt = new GysSmlt();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (gysSmlt.getId() == null || gysSmlt.getId() == 0);
        // set the related jbqk as a foreign key.
        gysSmlt.setJbqk( jbqk );
        gysSmltManager.save(gysSmlt);

        String key = (isNew) ? "gysSmlt.added" : "gysSmlt.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 